<template>
  <div>
    <div class="hc_view">
      <el-dialog
        title="操作确认"
        :visible.sync="dialogVisible"
        lock-scroll
        width="400px"
        :close-on-click-modal="true"
        :before-close="handleClose"
        :append-to-body="true"
      >
        <div class="dialog_div_1">
          <i :class="dialogData.classIcon" v-if="dialogData.classIcon != null"></i>
          <div>
            <p v-for="item in dialogData.textArr" v-html="item"></p>
          </div>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="cancel()" size="small" v-if="dialogData.cancelVisible">{{
            dialogData.cancelText
          }}</el-button>
          <el-button type="primary" @click="sure()" size="small">{{ dialogData.sureText }}</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    tipsData: Object,
  },
  data() {
    return {
      dialogVisible: false,
      index: 0,
      dialogData: {
        textArr: [],
        classIcon: 'el-icon-warning',
        sureText: '确 定',
        cancelText: '取 消',
        cancelVisible: true,
        dataLoading: false, // 数据请求状态
      },
    }
  },
  methods: {
    // 用户点击空白或者使用关闭按钮关闭弹窗执行该方法
    handleClose(done) {
      done() // 调用该方法完成后续操作
      this.$emit('onCancel')
    },
    onConfirm() {
      this.dialogVisible = !this.dialogVisible
      this.$emit('onConfirm', this.tipsData.tipsMark)
    },
    show(data) {
      Object.assign(this.$data.dialogData, this.$options.data().dialogData)
      this.dialogData.textArr = [data.text]
      this.index = data.index
      this.dialogVisible = true
      if (data.index == 0) {
        let that = this
        setTimeout(() => {
          this.hide()
        }, 2000)
      }
    },
    // 显示一个按钮，可以修改图标
    showOneBtn(classIcon, text, sureText) {
      Object.assign(this.$data.dialogData, this.$options.data().dialogData)
      this.dialogData.classIcon = classIcon
      this.dialogData.textArr = [text]
      this.dialogData.sureText = sureText
      this.dialogData.cancelVisible = false
      this.index = 1
      this.dialogVisible = true
    },
    // 显示两个按钮，可以修改图标
    showTwoBtn(classIcon, text, sureText, cancelText) {
      Object.assign(this.$data.dialogData, this.$options.data().dialogData)
      this.dialogData.classIcon = classIcon
      this.dialogData.textArr = [text]
      this.dialogData.sureText = sureText
      this.dialogData.cancelText = cancelText
      this.index = 1
      this.dialogVisible = true
    }, 
    // 显示两个按钮，可以修改图标
    showTwoBtnArr(classIcon, textArr, sureText, cancelText) {
      Object.assign(this.$data.dialogData, this.$options.data().dialogData)
      this.dialogData.classIcon = classIcon
      this.dialogData.textArr = textArr
      this.dialogData.sureText = sureText
      this.dialogData.cancelText = cancelText
      this.index = 1
      this.dialogVisible = true
    },
    hide() {
      this.dialogVisible = false
    },
    sure() {
      if (this.dialogData.dataLoading) {
        return
      }
      this.dialogData.dataLoading = true
      this.hide()
      this.$emit('onSure')
    },
    cancel() {
      if (this.dialogData.dataLoading) {
        return
      }
      this.dialogData.dataLoading = true
      this.hide()
      this.$emit('onCancel')
    },
  },
}
</script>

<style lang="scss" scoped>
.hc_view {
  ::v-deep .el-dialog {
    margin-top: 33vh !important;
    overflow: hidden;
    // background: transparent;
    box-shadow: none;
    -webkit-box-shadow: none;
    .el-dialog__body {
      padding: 0;
    }
    .el-dialog__header {
      box-sizing: border-box;
      display: flex;
      align-items: center;
      justify-content: space-between;
      border-bottom: transparent solid 0px;
      span {
        font-size: 0.300019rem;
        color: #666;
        font-weight: 600;
      }
      .el-dialog__headerbtn {
        position: static;
        .el-icon-close {
          color: #999;
          font-size: 0.48753rem;
        }
      }
    }
  }
}

.dialog_div {
  width: 100%;
  display: flex;
  justify-content: center;
  background-color: transparent;

  .dialog_content {
    width: 120px;
    height: 70px;
    background: rgba(229, 246, 255, 1);
    border: 1px solid #91d5fe;
    opacity: 1;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    .header_view {
      width: 100%;
      display: flex;
      justify-content: flex-end;
      background: transparent;
      padding: 5px 5px 0 0;
      i {
        font-size: 15px;
        color: #666;
      }
    }

    i {
      font-size: 15px;
      color: #1890fc;
    }
  }
}
.dialog_div_1 {
  display: flex;
  height: 100px;
  justify-content: center;
  align-items: center;
  .el-icon-warning {
    color: #fd5050;
    font-size: 43px;
    margin-right: 10px;
  }
  .el-icon-success {
    color: #52c41a;
    font-size: 43px;
    margin-right: 10px;
  }
  >div {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    >p {
      margin: 0;
      font-size: 14px;
      font-family: PingFang SC-Regular, PingFang SC;
      font-weight: 400;
      color: #666666;
      line-height: 24px;
    }
  }
}
.dialog-footer {
  display: flex;
  justify-content: center;
}
</style>
<style lang="scss">
.el-dialog__header {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: transparent solid 0px;
  span {
    font-size: 0.300019rem;
    color: #666;
    font-weight: 600;
  }
  .el-dialog__headerbtn {
    position: static;
    .el-icon-close {
      color: #999;
      font-size: 0.48753rem;
    }
  }
}
</style>
